<%@page import="com.lowagie.text.Cell"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%!public Date add10Day(Date d) {
		//10天超时，回复时间规定时间内未答复即超时
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(d);
		calendar.add(Calendar.DAY_OF_YEAR, 10);
		return calendar.getTime();
	}%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("basePath", basePath);
%>

<%
	int curr = 1;
	if (!nullOrEmpty(getParameter(request, "curr"))) {
		try {
			curr = Integer.parseInt(getParameter(request, "curr"));
		} catch (Exception e) {
			curr = 1;
		}
	}
	String sql = "SELECT * FROM APP_ZYFW t WHERE t.status <> 'C' ";
	List<Object> params = new ArrayList<Object>();
	sql += " order by t.CREATE_TIME desc";
	int total = queryForPageCount(sql, params);
	double pageSize = 10;
	int totalPage = (int) Math.ceil(total / pageSize);
	if (totalPage < curr) {
		curr = totalPage;
	}
	List<Map<String, Object>> list = queryForListPage(sql, params, curr, (int) pageSize);
	for (Map<String, Object> m : list) {
		Date d = (Date) m.get("create_time");
		String s = (String) m.get("status");
		Date replyTime = new Date();
		Date outTime = add10Day(d);
		if (!"A".equals(s)) {
			replyTime = (Date) m.get("reply_time");
		}
		if (outTime.getTime() > replyTime.getTime()) {
			m.put("out", false);
		} else {
			m.put("out", true);
		}
	}

	pageContext.setAttribute("curr", curr);
	pageContext.setAttribute("list", list);
	pageContext.setAttribute("total", total);
%>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>志愿服务</title>

<script type='text/javascript' src="${basePath }plugins/jquery/jquery-1.12.2.min.js"></script>
<link rel="stylesheet" href="${basePath }plugins/layui/v1.0.9/css/layui.css" media="all">
<link rel="stylesheet" href="css/jxw_css.css" />
<style type="text/css">
.question, .answer {
	overflow: hidden;
	width: 310px;
	display: inline-block;
	text-overflow: ellipsis;
	white-space: nowrap;
}
</style>
</head>
<body>
	<iframe id="top" name="top" title="网站头部" width="100%" height="211" src="/snxf/toub/top.shtml" scrolling="no" frameborder="0" allowtransparency="true"></iframe>
	<div class="secmain w1000 ovhid">
		<div class="secleft l ">
			<div class="wdbox">
				<form id="listForm" class="layui-form" action="">
					<input type="hidden" id="is_update" value="false">
					<input type="hidden" id="r" value="<%=System.currentTimeMillis()%>">
					<table class="layui-table">
						<thead>
							<tr>
								<th colspan="4" style="background-color: #E60611;color: white;vertical-align: middle;" valign="middle">
								<span style="font-size: 18px;">留言汇总</span>
								<a href="zyfw_save.jsp?r=<%=System.currentTimeMillis() %>" target="_blank" style="float: right;"><img src="images/luntan201603gxzpt_12.png" height="30" border="0" alt=""></a>
								</th>
							</tr>
						</thead>
						<thead>
							<tr>
								<th width="330">标题</th>
								<th width="180">时间</th>
								<th width="60">回复</th>
								<th width="60">状态</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${list }" var="zyfw">
								<tr>
									<td>
										<p class="question" title="${zyfw.title }"><a href="zyfw_detail.jsp?zyfw_id=${zyfw.zyfw_id }" target="_blank">${zyfw.title }</a></p>
									</td>
									<td>
										<fmt:formatDate value="${zyfw.create_time }" pattern="yyyy-MM-dd HH:mm" />
									</td>
									<td>
										<c:if test="${zyfw.status eq 'A' }">未回复</c:if>
										<c:if test="${zyfw.status eq 'B' }">
											<font color="green">已回复</font>
										</c:if>
									</td>
									<td align="center">
										<c:if test="${zyfw.out }">
											<font color="red">超时</font>
										</c:if>
										<c:if test="${!zyfw.out }">未超时</c:if>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<input type="hidden" id="curr" name="curr" value="${curr }">
					<div id="layerPage"></div>
				</form>
			</div>
		</div>
	<jsp:include page="zyfw_right.jsp"></jsp:include>
	<jsp:include page="zyfw_bottom.jsp"></jsp:include>
	<script type="text/javascript" src="${basePath }plugins/layui/v1.0.9/layui.js"></script>
	<script charset="utf-8" src="${basePath }plugins/97date/4.8/WdatePicker.js"></script>
	<script type='text/javascript'>
		layui.use('form', function() {
			var $ = layui.jquery, form = layui.form();
		});

		layui.use([ 'laypage', 'layer' ], function() {
			var laypage = layui.laypage, layer = layui.layer;
			laypage({
				cont : 'layerPage',
				curr : '${curr }',
				pages : Math.ceil('${total}' / 10),
				skip : true,
				jump : function(obj, first) {
					//得到了当前页，用于向服务端请求对应数据
					if (!first) {
						var index = layer.load(0, {
							shade : false
						});
						$("#curr").val(obj.curr);
						$("#listForm").submit();
					}
				}
			});
		});
	</script>
</body>
</html>